﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace peonwar
{
    static class AchievementManager
    {

        public static List<Achievements> AchievementList { get; private set; }
        public static int AchivementCount;
        public static int HauteurTotale;
        public static int nberofunlocked;
        public static void Initialize()
        {
            AchievementList = new List<Achievements>();


            Achievements ProfilCreated = new Achievements("", "", 1); // 0
            AchievementList.Add(ProfilCreated);
            Achievements Killer = new Achievements("", "", 1000); // 1
            AchievementList.Add(Killer);
            Achievements Play = new Achievements("", "", 30); // 2
            AchievementList.Add(Play);
            Achievements BomberMan = new Achievements("", "", 1); // 3
            AchievementList.Add(BomberMan);
            Achievements thowait = new Achievements("", "", 1); // 4
            AchievementList.Add(thowait);
            Achievements Master = new Achievements("", "", 1); // 5
            AchievementList.Add(Master);
            Achievements Level = new Achievements("", "", 1); // 6
            AchievementList.Add(Level);
            Achievements Social = new Achievements("", "", 10); // 7
            AchievementList.Add(Social);
            Achievements Combot = new Achievements("", "", 4); // 8
            AchievementList.Add(Combot);
            Achievements Ghost = new Achievements("", "", 1); // 9
            AchievementList.Add(Ghost);
            Achievements close = new Achievements("", "", 1); // 10
            AchievementList.Add(close);
            Achievements visito = new Achievements("", "", 1); // 11
            AchievementList.Add(visito);
            Achievements bullet = new Achievements("", "", 1); // 12
            AchievementList.Add(bullet);
            Achievements terror = new Achievements("", "", 1000000); // 13
            AchievementList.Add(terror);
            Achievements pre = new Achievements("", "", 1); // 14
            AchievementList.Add(pre);
            Achievements doc = new Achievements("", "", 1); // 15
            AchievementList.Add(doc);
            Achievements science = new Achievements("", "", 1); // 16
            AchievementList.Add(science);
            Achievements fistblood = new Achievements("" ,"", 8); // 17
            AchievementList.Add(fistblood);
            Achievements defence = new Achievements("", "", 1); // 18
            AchievementList.Add(defence);
            Achievements Psycho = new Achievements("", "", 50); // 19
            AchievementList.Add(Psycho);
            Achievements Jihad = new Achievements("", "", 10); // 20
            AchievementList.Add(Jihad);
            Achievements SuperSamo = new Achievements("", "", 1); // 21
            AchievementList.Add(SuperSamo);
            Achievements ArmyOfPeon = new Achievements("", "", 200); // 22
            AchievementList.Add(ArmyOfPeon);
            Achievements Provident = new Achievements("", "", 1); // 23
            AchievementList.Add(Provident);
            Achievements BadLuck = new Achievements("", "", 6); //24
            AchievementList.Add(BadLuck);

       
            AchivementCount = AchievementList.Count;
            HauteurTotale = (AchivementCount - 4) * 105;
            nberofunlocked = 0;
            for (int i = 0; i < AchievementManager.AchivementCount; i++)
            {
                if (!AchievementManager.AchievementList[i].locked)
                    nberofunlocked++;
            }
        }

        public static void SetAchievements()
        {
            for (int i = 0; i < AchievementList.Count; i++)
            {
                AchievementList[i].name = GameData.GameString[227 + 2*i];
                AchievementList[i].desc =GameData.GameString[227 + 2*i + 1];
            }
            nberofunlocked = 0;
            for (int i = 0; i < AchievementManager.AchivementCount; i++)
            {
                if (!AchievementManager.AchievementList[i].locked)
                    nberofunlocked++;
            }
        }

        public static void AchievementGet()
        {
            for (int i = 0; i < AchivementCount; i++)
            {
                if (i < SettingManager.CurrentProfil.AchievementList.Count)
                {
                    AchievementList[i].count = SettingManager.CurrentProfil.AchievementList[i];
                    if (AchievementList[i].count >= AchievementList[i].limit)
                        AchievementList[i].locked = false;
                }
                else
                    AchievementList[i].count = 0;
            }
            nberofunlocked = 0;
            for (int i = 0; i < AchievementManager.AchivementCount; i++)
            {
                if (!AchievementManager.AchievementList[i].locked)
                    nberofunlocked++;
            }
        }

        public static void AchievementSave()
        {
            for (int i = 0; i < AchivementCount; i++)
            {
                if (i < SettingManager.CurrentProfil.AchievementList.Count)
                    SettingManager.CurrentProfil.AchievementList[i] = AchievementList[i].count;
                else
                {
                    SettingManager.CurrentProfil.AchievementList.Add(AchievementList[i].count);
                }
            }
            SettingManager.SaveCurrentProfilFile();
            nberofunlocked = 0;
            for (int i = 0; i < AchievementManager.AchivementCount; i++)
            {
                if (!AchievementManager.AchievementList[i].locked)
                    nberofunlocked++;
            }
        }
    }
}
